"""
@title(TenX腾晓2024年12月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
@license(CC BY-SA 4.0 License)
"""
import os
from copy import deepcopy
from tkinter import YES


class TenXClass:
    def __init__(self):
        # 获取当前文件名并截取文件名的学号-姓名
        file_name = os.path.basename(__file__).split('.')[0].split("-")
        self.id = file_name[0]  # 学号
        self.name = file_name[1]  # 姓名

    @staticmethod
    def question1(*args) -> list[str]:
        binary_tree = deepcopy(args[0])  # 传入的地牢结构（二叉树），详细请看BinaryTree.py
        binary_tree = binary_tree.root
        a = []
        b = []
        c = {}
        d = 0
        e = []

        def suanfa(sth):
            nonlocal d
            while (sth.left != None and sth.right != None):
                a.append(sth)
                b.append(str(sth.value))
                if (sth.right != None):
                    c[d] = 'yes'
                if (sth.right == None):
                    c[d] = 'no'
                if (sth.left != None):
                    sth = sth.left
                    d = d + 1
                if (sth.left == None):
                    c[d] = 'no'
                    d = d + 1
                    suanfa(sth.right)
            if (sth.left == None and sth.right == None):
                if (sth.value == 0):
                    b.append(str(sth.value))
                    k = ''
                    A = 0
                    while A < len(b):
                        k = k + b(A)
                        A = A + 1
                    e.append(k)
                    d = d - 1
                    B = d
                    b.pop()
                    while B >= 0:
                        if c[B] == 'yes':
                            c[B] = 'no'
                            d = d + 1
                            suanfa(a[-1].right)
                        a.pop()
                        b.pop()
                        d = d - 1
                        B = d
                if (sth.value != 0):
                    d = d - 1
                    B = d
                    while B >= 0:
                        if c[B] == 'yes':
                            c[B] = 'no'
                            d = d + 1
                            suanfa(a[-1].right)
                        a.pop()
                        b.pop()
                        d = d - 1
                        B = d
            return e

        suanfa(binary_tree)
        return e

    @staticmethod
    def question2(*args) -> str:
        matrix = deepcopy(args[0])  # 传入的河流结构（矩阵）
        a = []
        i = 0
        j = 0
        while (i < len(matrix)):
            matrix[i].sort()
            a.append(matrix[i][-1])
            i = i + 1
        x = 0
        z = ''
        while (x < len(a)):
            z = z + str(a[x])
            x = x + 1
        return z

    @staticmethod
    def question3(*args) -> int:
        a = 52808343
        return a

    @staticmethod
    def question4(*args) -> int:
        n = deepcopy(args[0])  # 用于搭建金字塔的球个数
        a = 1
        b = 0
        c = 0
        while ((n - c) >= 0):
            b = b + a
            c = c + b
            a = a + 1
        return (a - 2)

    @staticmethod
    def question5(*args) -> str:
        balls = deepcopy(args[0])  # 五行空间球的初始值
        while (balls[0] < 10000 or balls[1] < 10000 or balls[2] < 10000 or balls[3] < 10000 or balls[4] < 10000):
            balls[0] = balls[3] + balls[4]
            if (balls[0] < 10000 or balls[1] < 10000 or balls[2] < 10000 or balls[3] < 10000 or balls[4] < 10000):
                balls[1] = balls[4] + balls[0]
                if (balls[0] < 10000 or balls[1] < 10000 or balls[2] < 10000 or balls[3] < 10000 or balls[4] < 10000):
                    balls[2] = balls[0] + balls[1]
                    if (balls[0] < 10000 or balls[1] < 10000 or balls[2] < 10000 or balls[3] < 10000 or balls[
                        4] < 10000):
                        balls[3] = balls[1] + balls[2]
                        if (balls[0] < 10000 or balls[1] < 10000 or balls[2] < 10000 or balls[3] < 10000 or balls[
                            4] < 10000):
                            balls[4] = balls[2] + balls[3]
                            continue
                    else:
                        break
                else:
                    break
            else:
                break
        a = [balls[0], balls[1], balls[2], balls[3], balls[4]]
        return a
